package com.ptu.spzx.controller;


import com.ptu.spzx.domain.file.Dto.FileDTO;
import com.ptu.spzx.model.vo.common.Result;
import com.ptu.spzx.service.IFileService;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author YT
 * @since 2024-01-28
 */
@RestController
@RequestMapping("/sc/exam/file")
public class FileController {
    @Autowired
    private IFileService fileService;
    // 1   上传
    @PostMapping("/addExamFile")
    @PreAuthorize("@permissionService.hasPermission('exam:file:addExamFile')")
    public Result upload(FileDTO fileDTO) throws IOException {
        return fileService.upload(fileDTO);

    }


    //    下载
    @GetMapping("/download/{fileName}")
    @PreAuthorize("@permissionService.hasPermission('exam:file:download')")
    public void download(@PathVariable String fileName, HttpServletResponse response) throws IOException {
        fileService.download(fileName, response);
    }
}

